import req from '@/utils/request.js';
import * as URL from '@/constants/api.js';

export function getSuggestionList(searchValue) {
  return req({
    url: URL.SUGGESTION_LIST,
    params: {
      q: searchValue,
    },
  })
    .then((res) => res.data.data.options.filter(o => o?.trim()))
    .catch(() => []);
}

export function getSearchResult(index) {
  return req({
    method: 'get',
    url: URL.SEARCH_RESULT,
    params: {
      q: index,
    }
  })
    // 处理成功
    .then(res => res.data.data.results)
    // 处理错误
    .catch(() => []);
}
